﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VFCons
{
	public partial class ROIPanel : UserControl
	{
		public EventHandler BoxSelectionClick;
		public ROIPanel()
		{
			InitializeComponent();
			buttonSelect.Click += (s, e) =>
			{
				if (BoxSelectionClick != null) BoxSelectionClick(s, e);
			};
		}

		private int _x = 0;
		public int X
		{
			get { return _x; }
			set { _x = value;textBoxX.Text = _x.ToString(); }
		}

		private int _y = 0;
		public int Y
		{
			get { return _y; }
			set { _y = value; textBoxY.Text = _y.ToString(); }
		}

		private int _w = 0;
		public int W
		{
			get { return _w; }
			set { _w = value; textBoxW.Text = _w.ToString(); }
		}

		private int _h = 0;
		public int H
		{
			get { return _h; }
			set { _h = value; textBoxH.Text = _h.ToString(); }
		}

		public bool BoxCheckEnable { 
			set
			{
				if (value == false)
				{
					if (buttonSelect.Enabled)
					{
						buttonSelect.Enabled = false;
						buttonSelect.BackColor = SystemColors.Control;
					}
				}
				else
				{
					if (buttonSelect.Enabled == false)
					{
						buttonSelect.Enabled = true;
					}
				}
			}
		}

		public bool UI2Data()
		{
			try
			{
				int x = Convert.ToInt32(textBoxX.Text);
				int y = Convert.ToInt32(textBoxY.Text);
				int w = Convert.ToInt32(textBoxW.Text);
				int h = Convert.ToInt32(textBoxH.Text);

				_x = x;
				_y = y;
				_w = w;
				_h = h;
				return true;
			}
			catch (Exception ex)
			{
				return false;
			}
		}
	}
}
